﻿
namespace Hotel.Classes.Helper
{
    using System;
    using System.Data;

    /// <summary>
    /// Get all type of data info from DB item
    /// </summary>
    public class DataHelper
    {
        public static string Get(object columnData)
        {
            try
            {
                if (!(columnData == DBNull.Value || columnData == null))
                {
                    return columnData.ToString();
                }
            }
            catch { }
            return string.Empty;
        }



        public static string Get(DataRow row, string columnName)
        {
            try
            {
                if (row.Table.Columns.IndexOf(columnName) >= 0)
                {
                    return Get(row[columnName]);
                }
            }
            catch { }
            return string.Empty;
        }


        public static long GetLong(object columnData)
        {
            string data = Get(columnData);
            long val = 0;
            long.TryParse(data, out val);
            return val;
        }

        public static long GetLong(DataRow row, string columnName)
        {
            string data = Get(row, columnName);
            long val = 0;
            long.TryParse(data, out val);
            return val;
        }

        public static int GetInt(object columnData)
        {
            string data = Get(columnData);
            int val = 0;
            int.TryParse(data, out val);
            return val;
        }

        public static int GetInt(DataRow row, string columnName)
        {
            string data = Get(row, columnName);
            int val = 0;
            int.TryParse(data, out val);
            return val;
        }

        public static decimal GetDecimal(object columnData)
        {
            string data = Get(columnData);
            decimal val = 0;
            decimal.TryParse(data, out val);
            return val;
        }

        public static decimal GetDecimal(DataRow row, string columnName)
        {
            string data = Get(row, columnName);
            decimal val = 0;
            decimal.TryParse(data, out val);
            return val;
        }

        public static double GetDouble(object columnData)
        {
            string data = Get(columnData);
            double val = 0;
            double.TryParse(data, out val);
            return val;
        }

        public static double GetDouble(DataRow row, string columnName)
        {
            string data = Get(row, columnName);
            double val = 0;
            double.TryParse(data, out val);
            return val;
        }

        public static bool GetBool(object columnData)
        {
            string data = Get(columnData);
            bool val = false;
            bool.TryParse(data, out val);
            return val;
        }

        public static bool GetBool(DataRow row, string columnName)
        {
            string data = Get(row, columnName);
            bool val = false;
            bool.TryParse(data, out val);
            return val;
        }

        public static DateTime GetDate(object columnData)
        {
            string data = Get(columnData);
            DateTime val = DateTime.Now;
            DateTime.TryParse(data, out val);
            return val;
        }

        public static DateTime GetDate(DataRow row, string columnName)
        {
            string data = Get(row, columnName);
            DateTime val = DateTime.Now;
            DateTime.TryParse(data, out val);
            return val;
        }


        public static string GetFormatedString(string prefix_Imagetype, string StoryCode, string ext)
        {
            string strFormatedFileNmae = prefix_Imagetype + StoryCode + ext;
            return strFormatedFileNmae;
            //return  SettingsMS.FileuploadPhysical  "\\StoryImages\\" + filePrefix + txtStoryCode.Text + Path.GetExtension(cntrlUpload.FileName);
        }
    }
}